package spindles.api.util;

import java.math.BigDecimal;

import org.jscience.mathematics.vectors.Float64Matrix;
import org.jscience.mathematics.vectors.Float64Vector;

public class MathUtil {
	
	public static double[][] toDouble(Float64Matrix m){
		int nrows = m.getNumberOfRows();
		int ncols = m.getNumberOfColumns();
		double result[][] = new double[nrows][ncols];
		for(int i = 0; i < nrows; i++){
			Float64Vector v = m.getRow(i);
			result[i] = toDouble(v);
		}
		
		return result;
	}
	
	public static double[] toDouble(Float64Vector v){
		int size = v.getDimension();
		double[] result = new double[size];
		
		for(int i = 0; i < size; i++){
			result[i] = v.getValue(i);
		}
		return result;
	}
	

	public static double[][] transpose(double[][] data) {
		Float64Matrix m = Float64Matrix.valueOf(data).transpose();		
		return toDouble(m);
	}	
	
	public static boolean isBetween(BigDecimal value, int bottomLimit, int upperLimit){
		return (value.compareTo(new BigDecimal(bottomLimit)) >= 0) && 
			   (value.compareTo(new BigDecimal(upperLimit)) <= 0);
	}

}
